package com.jiuzhou.services.taobao.impl;

import javax.management.JMException;

import org.springframework.stereotype.Service;

import com.jiuzhou.crawlers.taobao.pipeline.taobao.TaoBaoPipeline;
import com.jiuzhou.crawlers.taobao.processor.taobao.TaoBaoProcessor;
import com.jiuzhou.crawlers.taobao.processor.taobao.constant.CommonConstant;
import com.jiuzhou.services.taobao.IStartTaobaoService;

import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.monitor.SpiderMonitor;

@Service("StartCrawlerService")
public class StartTaobaoServiceImpl implements IStartTaobaoService{

	@Override
	public String goKeyWords() throws JMException {
		 CommonConstant.KEYWORD=""; //需要抓取商品的关键词, 注意：该关键词需要在淘宝搜索时有品牌
		 CommonConstant.CURRENTTYPE=""+CommonConstant.KEYWORD;  //抓取网页过程中，意外停止时的关键词
		 //爬虫主要信息设置
		 //String list = "https://s.taobao.com/search?q="+ CommonConstant.KEYWORD+"&";
		 String list ="https://www.taobao.com/tbhome/page/market-list?spm=a21bo.50862.1997563209.1.l6tdql";	 
		  Spider oschinaSpider = Spider.create(new TaoBaoProcessor())
		  .addUrl(list).addPipeline(new TaoBaoPipeline("hdfs://master:9000/user/yanganzhen/taobao/"));
		  SpiderMonitor.instance().register(oschinaSpider);
		  oschinaSpider.start();
		  return "success";
	}

}
